<template>
	<view :style="skin" class="inStock">
		<view class="stockMain">
			<block v-if="deviceInfoShow">
				<view class="stockTitle">
					<view>
						{{$t('property.dailyjudgment')}}
					</view>
					<view>
						{{$t('lease.QuantitytoCount')}}{{needNum}},{{$t('lease.QuantityCounted')}}{{wellAs}}
					</view>
				</view>

				<view class="deviceTypeList flex-c-SB" v-for="(item,index) in deviceTypeList" :key="index"
					@click="changeDeviceType(item)">
					<u--image :src="'https://test24.giraffepowa.com'+item.photo" width="75px" height="75px"></u--image>
					<view
						:class="item.typeCheck == 2?'deviceTypeInfo checkSuccess flex-c-SB-c':item.typeCheck == 3?'deviceTypeInfo checkErr flex-c-SB-c':'deviceTypeInfo flex-c-SB-c'">
						<view>
							{{item.productModel}}
						</view>
						<view class="">
							({{$t('lease.tenantable')}}{{item.tenantable||0}},{{$t('lease.reserve')}}{{item.reserve || 0}})
						</view>

						<text class="iconfont icon-a-mingchengarrow_right iconRight"></text>
						<!-- <text v-if="item.typeCheck == 1" class="iconfont icon-a-mingchengclose-circle-line  iconStatus"></text> -->
						<view class="iconStatus" v-if="item.typeCheck == 1">
							<u-loading-icon size="24"></u-loading-icon>
						</view>
						<text v-else-if="item.typeCheck == 2"
							class="iconfont icon-a-mingchengcheckbox-circle-line  iconStatus"></text>
						<text v-else-if="item.typeCheck == 3" class="iconfont icon-a-mingchengclose-circle-line  iconStatus"></text>
						<text v-else-if="item.typeCheck == 0" class="iconfont icon-a-mingchengclose-circle-line  iconStatus"></text>

					</view>
				</view>
			</block>
			<block v-else>
				<view
					:class="typeCheckStatus == 2?'stockTitle checkSuccess':typeCheckStatus == 3?'stockTitle checkErr':'stockTitle'">
					<text class="iconfont icon-a-mingchengarrow_left iconBack" @click="deviceInfoShow = true"></text>
					<view>
						{{actionType.productModel}}
					</view>
				</view>

				<view class="deviceTypeList flex-c-SB" v-for="(item,index) in deviceList" :key="index">
					<u--image shape="circle" :src="'https://test24.giraffepowa.com'+item.photo" width="75px"
						height="75px"></u--image>
					<view
						:class="item.isCheck == 2?'deviceTypeInfo checkSuccess flex-c-SB-c':item.isCheck == 3?'deviceTypeInfo checkErr flex-c-SB-c':'deviceTypeInfo flex-c-SB-c'"
						@click="handleDevice(item)">
						<view>
							<view>{{$t('lease.productID')}}:{{item.productId}}</view>
							<view>{{$t('lease.battery')}}:{{item.battery}}%</view>
							<view>
								{{$t('lease.status')}}:{{item.stockStatus == 1?$t('lease.tenantable'):item.stockStatus == 2?$t('lease.reserve'):''}}
							</view>
						</view>
						<view>

							<text v-if="item.isCheck == 2" class="iconfont icon-a-mingchengcheckbox-circle-line  iconStatus"></text>
							<text v-else-if="item.isCheck == 3" class="iconfont icon-a-mingchengclose-circle-line  iconStatus"></text>
							<text v-else-if="item.isCheck == 0" class="iconfont icon-a-mingchengclose-circle-line  iconStatus"></text>
							<view class="iconStatus" v-else-if="item.isCheck == 1">
								<u-loading-icon size="24"></u-loading-icon>
							</view>

						</view>

					</view>
				</view>

			</block>

		</view>

		<!-- 一件盘点 -->
		<u-button customStyle="margin-top: 8px;" v-if="btnStatus == 1" :disabled="!isCheck" @click="handleCheck"
			color="var(--subjectColor)">{{$t('property.stockCheck')}}(00:00~24:00)</u-button>
		<!-- 盘点中 -->
		<u-button customStyle="margin-top: 8px;" v-else-if="btnStatus == 2" :disabled="true"
			color="#bebebe">{{$t('property.TakingStock')}}<u-loading-icon size="24"></u-loading-icon></u-button>
		<!-- 盘点成功 -->
		<u-button customStyle="margin-top: 8px;" v-else-if="btnStatus == 3" color="#a2ef4d"
			@click="btnStatus = 1">{{$t('property.SuccessfulInventory')}}</u-button>
		<u-button customStyle="margin-top: 8px;" v-else-if="btnStatus == 4" @click="unusualShow = true"
			color="#bd3124">{{$t('property.InventoryAnomaly')}}({{errorArr.length}})</u-button>

		<!-- 盘点异常弹框 -->
		<u-popup :show="unusualShow" mode="center" :closeOnClickOverlay="false" round="8" closeable @close="closePopup">
			<view class="popupBox">
				<view class="title">
					{{$t('property.ExceptionList')}}
				</view>
				<view class="checkListMain">
					<view v-for="(item,index) in errorArr" :key="index" @click="changeDevice(item,index)">
						<view :class="handelIndex == index?'mt16 errBorder flex-c-SB':'mt16 flex-c-SB'">
							<u--image shape="circle" :src="src" width="75px" height="75px"></u--image>
							<view class="deviceTypeInfo checkErr">
								<view>
									{{$t('lease.productModel')}}:{{item.productModel}}
								</view>
								<view>
									{{$t('lease.productID')}}:{{item.productId}}
								</view>
								<view>
									<view class="iconStatus" v-if="item.isCheck == 1">
										<u-loading-icon size="24"></u-loading-icon>
									</view>

									<text v-else-if="item.isCheck == 2"
										class="iconfont icon-a-mingchengcheckbox-circle-line  iconStatus"></text>
									<text v-else-if="item.isCheck == 3"
										class="iconfont icon-a-mingchengclose-circle-line  iconStatus"></text>
									<text v-else-if="item.isCheck == 0"
										class="iconfont icon-a-mingchengclose-circle-line  iconStatus"></text>
									<!-- {{item.isCheck == 0?'未盘点':item.isCheck == 1?'盘点中':item.isCheck == 2?'盘点成功':item.isCheck == 3?'盘点失败':''}} -->
								</view>
							</view>
						</view>

					</view>
				</view>


				<view class="popupBtn">
					<u-button color="var(--subjectColor)" :disabled="disableAgein"
						@click="handleLost">{{$t('property.LossRevolution')}}</u-button>
					<u-button color="var(--subjectColor)" :disabled="disableAgein"
						@click="handleMal">{{$t('property.failOver')}}</u-button>
				</view>
				<view class="popupBtn">
					<u-button color="var(--subjectColor)" :disabled="disableAgein"
						@click="againCheck">{{$t('property.Checkabnormal')}}</u-button>
				</view>

			</view>
		</u-popup>


		<u-modal showCancelButton :show="modelShow" content='Inventory, whether to exit' @confirm="modelConfirm"
			@cancel="modelCancel" confirmText="confirm" cancelText="cancel"></u-modal>

	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex'
	import {
		getDeviceTypeToId,
		getInStoreAll,
	} from '@/utils/sql/sqlDevice.js'

	import {
		pidToMAC,
		formatHexString,
		dataTran,
		mulDataDevice,
		addColonEveryTwoChars,
		repetitionDataMac,
		encryption
	} from '@/utils/index.js'
	import {
		getDeviceType,
	} from '@/utils/sql/sqlDeviceType.js'
	import {
		ckOnline,
		ckDetails
	} from '@/api/deviceCheck.js'
	import {
		adressAuthority
	} from '@/utils/jurisdiction.js'
	export default {
		data() {
			return {
				needNum: 0,
				wellAs: 0,
				value: '',
				// 是否进入设备类型详情
				deviceInfoShow: true,
				unusualShow: false,
				actionType: {},
				src: '',
				ble: uni.requireNativePlugin('ble'),
				deviceList: [],
				checkList: [], //需要盘点的数据列表
				checkIndex: 0,
				deviceTypeList: [], //设备品类
				tipsTime: null,
				errTipsTime: null,
				time: null,
				errTime: null,

				againObj: {},

				errorArr: [], //盘点后的异常列表
				errIndex: 0,
				btnStatus: 1,
				typeCheckStatus: 0, //设备品类的状态

				handelIndex: 0, //异常清单，选中的下标

				ckDetail: null,
				disableAgein: false,
				modelShow: false,
			};
		},
		computed: {
			...mapState({
				skin: state => state.theme.skin
			}),
			isCheck() {
				const now = new Date();
				const hours = now.getHours();
				// 调试 22
				// return hours >= 8 && hours < 24;
				return true;
			}

		},
		beforeDestroy() {
			clearInterval(this.time);
			clearTimeout(this.tipsTime);
		},
		mounted() {
			// this.ble = uni.requireNativePlugin('ble');
			this.ble.init();
			this.ble.start();
			this.getDeviceType();
			this.getInsAllDevi();
			let that = this;
			uni.$on('changeSwitch', async function(data) {
				console.log('切换switch', !that.deviceInfoShow);
				that.ble.init();
				that.ble.start();
				await that.getDeviceType();
				await that.getInsAllDevi();
				if (!that.deviceInfoShow) {
					setTimeout(() => {
						that.changeDeviceType(that.actionType)
					}, 1000)

				}
			})
			uni.$on('lostBack', function() {
				console.log('lostBack');
				that.handelIndex = 0;
				that.errIndex = 0;
				that.ble.init();
				that.ble.start();
				that.getDeviceType();
				that.getInsAllDevi();
			})
		},
		methods: {
			modelCancel() {
				this.modelShow = false
			},
			modelConfirm() {
				clearTimeout(this.errTipsTime);
				clearInterval(this.errTime);
				this.errorArr[this.errIndex].isCheck = 3
				this.errIndex = 0;
				this.disableAgein = false;
				this.unusualShow = false;
				this.modelShow = false;
			},
			closePopup() {
				if (this.disableAgein) {
					this.modelShow = true
				} else {
					this.unusualShow = false
				}


			},
			handleLost() {
				let appearObj = this.errorArr[this.handelIndex]
				console.log(appearObj);
				uni.navigateTo({
					url: `/pages/property/faultLost/faultLost?appearObj=${JSON.stringify(appearObj)}`
				})
				this.unusualShow = false
			},
			handleMal() {
				let appearObj = this.errorArr[this.handelIndex]
				uni.navigateTo({
					url: `/pages/property/faultReporting/faultReporting?appearObj=${JSON.stringify(appearObj)}&type=return`
				})
				this.unusualShow = false
			},
			changeDevice(item, index) {
				this.handelIndex = index
			},
			againCheck() {
				let that = this

				this.ble.isUiThreadOpenGPS(function(res) {
					console.log('接收', res.code); //-1为未开 1为已开
					if (res.code == -1) {
						uni.showToast({
							title: 'Please turn on positioning',
							icon: 'none'
						})
						return
					}

					adressAuthority().then(res => {
						console.log(res);
						// 判断蓝牙是否打开
						uni.openBluetoothAdapter({
							success() {

								that.disableAgein = true
								that.handelIndex = 0;
								that.errIndex = 0;
								that.errorSendOrder();
								that.getErrMeg();

							},
							fail() {
								uni.showToast({
									title: 'Bluetooth is off',
									icon: 'none'
								})
								return false
							},
						})
					})
				});



			},
			async getDeviceType() {
				let res = await getDeviceType();
				res.data.map(item => {
					return item.typeCheck = 0 //   0 未盘点 1 盘点中 2盘点成功(设备在库) 3 盘点失败(设备不在库或者设备无响应)
				})
				this.deviceTypeList = res.data
			},
			// 获取所有的在库和预定的设备
			getInsAllDevi() {
				getInStoreAll().then(res => {
					console.log(res);
					res.data.map(item => {
						return item.isCheck = 0, item.battery = JSON.parse(item.productProperty).battery
					})
					this.checkList = res.data
					this.needNum = res.data.length

					ckDetails().then(ckres => {
						console.log(ckres);
						if (ckres.code == 0 && ckres.data) {
							let ckDetail = JSON.parse(ckres.data.ckDetail);
							this.wellAs = ckres.data.ckSizeSucc
							ckDetail.map(item => {
								this.checkList.map(item1 => {
									if (item1.productId == item.productId && item
										.ckStatus == 0) {
										return item1.isCheck = 2
									} else if (item1.productId == item.productId && item
										.ckStatus == 1) {
										return item1.isCheck = 3
									}
								})
							})

							this.errorArr = this.checkList.filter(item => {
								return item.isCheck != 2
							})
							console.log(this.deviceTypeList);

							for (let item of this.deviceTypeList) {
								let newArr = this.checkList.filter((obj) => obj.productModel === item
									.productModel);
								if (newArr.every((obj) => obj.isCheck === 2)) {
									item.typeCheck = 2;
								} else {
									item.typeCheck = 3;
								}
							}

						} else if (ckres.code == 0 && ckres.data == null) {
							this.btnStatus = 1
							this.errorArr = []
							this.checkList.map(item => {
								return item.isCheck = 3
							})
						} else if (ckres.code == 1) {
							this.btnStatus = 1
							this.errorArr = []
							this.checkList.map(item => {
								return item.isCheck = 3
							})
						}

					})

				})
			},

			setSuccessCheck(dataList) {
				let ckDetails = this[dataList].map(item => {
					return {
						ckStatus: 0,
						productId: item.productId,
						productModel: item.productModel
					}
				})
				ckOnline({
					ckDetail: encryption(JSON.stringify(ckDetails))
				}).then(res => {
					console.log(res);
				})
			},
			setErrorCheck(dataList) {
				let ckDetails = this[dataList].map(item => {
					if (item.isCheck == 2) {
						return {
							ckStatus: 0,
							productId: item.productId,
							productModel: item.productModel
						}
					} else if (item.isCheck == 3) {
						return {
							ckStatus: 1,
							ecDesc: "abnormal",
							productId: item.productId,
							productModel: item.productModel
						}
					}

				})
				console.log(ckDetails);
				ckOnline({
					ckDetail: encryption(JSON.stringify(ckDetails))
				}).then(res => {
					console.log(res);
				})
			},
			timePopup() {
				console.log('倒计时', this.checkIndex);
				let that = this
				this.tipsTime = setTimeout(() => {
					console.log('倒计时', that.checkIndex, that.checkList.length);
					that.checkList.map((item, index) => {
						if (index == that.checkIndex) {
							return item.isCheck = 3
						}
					})

					let typeObj = that.checkList[that.checkIndex];
					that.deviceTypeList.map(item => {
						if (item.productModel == typeObj.productModel) {
							return item.typeCheck = 3
						}
					})


					if (that.checkIndex < that.checkList.length - 1) {
						console.log('再次发送', that.checkIndex);
						clearTimeout(that.tipsTime);
						that.checkIndex++;
						that.sendOrder()
					} else {
						clearTimeout(that.tipsTime);
						// 全部发送广播后，两S后不再监听
						setTimeout(async () => {
							clearInterval(that.time);

							let checkOver = that.checkList.every(item => {
								return item.isCheck == 2
							})
							if (checkOver) {
								uni.showToast({
									title: 'Inventory Successful',
									icon: 'none'
								})
								that.btnStatus = 3

								that.setSuccessCheck('checkList')

							} else {
								that.errorArr = that.checkList.filter(item => {
									return item.isCheck != 2
								})

								await that.setErrorCheck('checkList')

								that.btnStatus = 4
							}

						}, 2000)

						console.log('已经全部发送');
					}
				}, 3000)
			},
			getErrMeg() {
				let that = this;
				this.errTime = setInterval(() => {
					console.log('倒计时');
					that.ble.getBackData(function(res) {
						console.log(res);
						// if(that.checkIndex == 0){
						// 	res.data = [
						// 		{
						// 			msg:'09ff8225ebaf975b690100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
						// 			mac:'00:00:0E:48:68:52'
						// 		}
						// 	]
						// }

						if (res.data.length > 0) {
							let result = repetitionDataMac(res.data, 130, that.errorArr[that.errIndex]
								.productId);
							console.log(result);
							if (result) {
								clearTimeout(that.errTipsTime);
								uni.showToast({
									title: result.msg,
									icon: 'none'
								})
								let data = dataTran(result.msg) //处理设备返回的信息
								that.ble.littleEndianStringToInt(data.littleNum, function(res) {
									data.num = res.data
									console.log(data, '========================');

									//设备在库
									if (data.num == 0) {
										that.errorArr.map((item, index) => {
											if (index == that.errIndex) {
												return item.isCheck = 2
											}
										})

									} else if (data.num == 1 || data.num == 2) { //设备租出去或者等待归还
										that.errorArr.map((item, index) => {
											if (index == that.errIndex) {
												return item.isCheck = 3
											}
										})
									}

									if (that.errIndex < that.errorArr.length - 1) {
										that.errIndex++;
										that.errorSendOrder()
									} else {
										clearTimeout(that.errTipsTime);
										clearInterval(that.errTime);
										// 全部发送广播后，两S后不再监听 以及清空过滤条件
										setTimeout(() => {
											console.log('全部发送广播后，两S后不再监听');
											// that.ble.resetMac();
											let checkOver = that.errorArr.every(item => {
												return item.isCheck == 2
											})
											if (checkOver) {
												uni.showToast({
													title: 'Inventory Successful',
													icon: 'none'
												})
												that.unusualShow = false
												that.setSuccessCheck('errorArr')
											} else {
												that.errorArr = that.errorArr.filter(
													item => {
														return item.isCheck != 2
													})
												that.setErrorCheck('errorArr')
											}

										}, 2000)

										console.log('已经全部发送');
									}

								})
							}
						}
					})
				}, 2000)
			},
			getMeg() {
				let that = this;
				this.time = setInterval(() => {
					console.log('倒计时');
					that.ble.getBackData(function(res) {
						console.log(res);
						console.log(that.checkList[that.checkIndex].productId);
						// if(that.checkIndex == 0){//e486852
						// 	res.data = [
						// 		{
						// 			msg:'09ff8225ebaf975b690000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
						// 			mac:'00:00:0E:48:68:52',
						// 		}
						// 	]
						// }

						if (res.data.length > 0) {
							let result = repetitionDataMac(res.data, 130, that.checkList[that.checkIndex]
								.productId);
							console.log(result);
							if (result) {
								clearTimeout(that.tipsTime);
								uni.showToast({
									title: result.msg,
									icon: 'none'
								})
								let data = dataTran(result.msg) //处理设备返回的信息
								that.ble.littleEndianStringToInt(data.littleNum, function(res) {
									data.num = res.data
									console.log(data, '========================');
									//设备在库
									if (data.num == 0) {
										that.checkList.map((item, index) => {
											if (index == that.checkIndex) {
												return item.isCheck = 2
											}

										})

										let typeObj = that.checkList[that.checkIndex];

										let checkOverView = that.checkList.every(item => {
											return item.isCheck == 2
										})
										if (checkOverView) {
											that.deviceTypeList.map(item => {
												if (item.productModel == typeObj
													.productModel) {
													return item.typeCheck = 2
												}
											})
										}


									} else if (data.num == 1 || data.num == 2) { //设备租出去或者等待归还
										that.checkList.map((item, index) => {
											if (index == that.checkIndex) {
												return item.isCheck = 3
											}
										})

										let checkOverView = that.checkList.some(item => {
											return item.isCheck == 3
										})
										console.log(checkOverView);

										if (checkOverView) {
											let typeObj = that.checkList[that.checkIndex];
											that.deviceTypeList.map(item => {
												if (item.productModel == typeObj
													.productModel) {
													return item.typeCheck = 3
												}
											})
										}
									}

									if (that.checkIndex < that.checkList.length - 1) {
										that.checkIndex++;
										that.sendOrder()
									} else {
										clearTimeout(that.tipsTime);
										clearInterval(that.time);
										// 全部发送广播后，两S后不再监听 以及清空过滤条件
										setTimeout(async () => {

											// that.ble.resetMac();

											for (let item of that.deviceTypeList) {
												let newArr = that.checkList.filter((
														obj) => obj
													.productModel === item
													.productModel);
												if (newArr.every((obj) => obj
														.isCheck === 2)) {
													item.typeCheck = 2;
												} else {
													item.typeCheck = 3;
												}
											}

											let checkOver = that.checkList.every(
												item => {
													return item.isCheck == 2
												})
											if (checkOver) {
												uni.showToast({
													title: 'Inventory Successful',
													icon: 'none'
												})
												that.setSuccessCheck('checkList')
												that.btnStatus = 3

											} else {l
												that.errorArr = that.checkList.filter(
													item => {
														return item.isCheck != 2
													})
												await that.setErrorCheck('checkList')
												that.btnStatus = 4
											}

										}, 2000)
										console.log('已经全部发送');
									}

								})
							}
						}
					})
				}, 2000)
			},
			// 重新盘点异常
			errorSendOrder() {
				console.log(this.errIndex);
				let productId = this.errorArr[this.errIndex].productId

				this.errorArr.map((item, index) => {
					if (index == this.errIndex) {
						return item.isCheck = 1
					}
				})


				// 发送的命令mac反转,返回的数据不需要反转

				let deviceMAC = pidToMAC(productId) //产品的PID转为设备MAC地址 转16进制 不足12位，前面0补
				let deviceMAC16 = formatHexString(deviceMAC) //反转并且加上:
				console.log(deviceMAC, deviceMAC16);

				let order = (30).toString(16);
				let code = order + deviceMAC16;


				let char = addColonEveryTwoChars(deviceMAC)

				this.ble.sendCmd(code, 3, char);
				setTimeout(() => {
					this.ble.stopSendCmd()
				}, 1000)
				this.errorTimePopup();

			},
			errorTimePopup() {
				let that = this
				this.errTipsTime = setTimeout(() => {
					console.log('倒计时', that.errIndex, that.errorArr.length);
					that.errorArr.map((item, index) => {
						if (index == that.errIndex) {
							return item.isCheck = 3
						}
					})



					if (that.errIndex < that.errorArr.length - 1) {
						console.log('再次发送', that.errIndex);
						clearTimeout(that.errTipsTime);
						that.errIndex++;
						that.errorSendOrder()
					} else {
						clearTimeout(that.errTipsTime);
						// 全部发送广播后，两S后不再监听
						setTimeout(() => {
							clearInterval(that.errTime);
							that.disableAgein = false
							let checkOver = that.errorArr.every(item => {
								return item.isCheck == 2
							})
							if (checkOver) {
								uni.showToast({
									title: 'Inventory Successful',
									icon: 'none'
								})
								that.unusualShow = false
								that.setSuccessCheck('errorArr')
							} else {
								that.errorArr = that.errorArr.filter(item => {
									return item.isCheck != 2
								})
								that.setErrorCheck('errorArr')
							}

						}, 2000)

						console.log('已经全部发送');
					}
				}, 3000)
			},
			sendOrder() {
				console.log(this.checkIndex);
				let productId = this.checkList[this.checkIndex].productId

				this.checkList.map((item, index) => {
					if (index == this.checkIndex) {
						return item.isCheck = 1
					}
				})

				let typeObj = this.checkList[this.checkIndex];
				this.deviceTypeList.map(item => {
					if (item.productModel == typeObj.productModel) {
						return item.typeCheck = 1
					}
				})

				// 发送的命令mac反转,返回的数据不需要反转

				let deviceMAC = pidToMAC(productId) //产品的PID转为设备MAC地址 转16进制 不足12位，前面0补
				let deviceMAC16 = formatHexString(deviceMAC) //反转并且加上:
				console.log(deviceMAC, deviceMAC16);

				let order = (30).toString(16); //设备在库

				let code = order + deviceMAC16

				let char = addColonEveryTwoChars(deviceMAC)
				console.log(code, char, order);

				this.ble.sendCmd(code, 3, char);
				this.wellAs++;
				setTimeout(() => {
					this.ble.stopSendCmd()
				}, 1000)
				this.timePopup();

			},
			handleCheck() {
				let that = this
				this.ble.isUiThreadOpenGPS(function(res) {
					console.log('接收', res.code); //-1为未开 1为已开
					if (res.code == -1) {
						uni.showToast({
							title: 'Please turn on positioning',
							icon: 'none'
						})
						return
					}

					adressAuthority().then(res => {
						console.log(res);
						console.log(that.checkList);
						if(that.checkList.length == 0){
							uni.showToast({
								title:'No Device',
								icon:'none'
							})
							return false
						}
						// 判断蓝牙是否打开
						uni.openBluetoothAdapter({
							success() {

								that.wellAs = 0
								that.checkIndex = 0
								that.btnStatus = 2
								uni.setStorageSync('uncounted', false)
								uni.$emit('deviceCheckSu')
								that.sendOrder()
								that.getMeg()

							},
							fail() {
								uni.showToast({
									title: 'Bluetooth is off',
									icon: 'none'
								})
								return false
							},
						})
					})
				});



			},
			handleDevice(item) {
				this.unusualShow = true
				this.againObj = item

			},
			async changeDeviceType(item) {
				this.typeCheckStatus = item.typeCheck
				this.deviceInfoShow = false
				this.actionType = item
				console.log(item);
				await this.getDevice(item.productModel, item.photo);

				// clearInterval(this.time);
				// clearTimeout(this.tipsTime);
			},
			async getDevice(productModel, photo) {
				this.deviceList = this.checkList.filter(item => {
					return item.productModel == productModel
				})
				this.deviceList.map(item => {
					return item.photo = photo
				})
				console.log(this.checkList);
				// let res = await getDeviceTypeToId(productModel)
				// if (res.code == 0) {
				// 	this.deviceList = res.data.filter(item => {
				// 		return item.stockStatus == 1 || item.stockStatus == 2
				// 	})
				// 	this.deviceList.map(item => {
				// 		return item.battery = JSON.parse(item.productProperty).battery
				// 	})
				// }
			},
		},

	}
</script>

<style lang="scss" scoped>
	.inStock {
		padding: 16px;
		box-sizing: border-box;
		height: 100%;

		.checkSuccess {
			background-color: #a2ef4d !important;
		}

		.checkErr {
			background-color: #bd3124 !important;
		}

		.stockMain {
			width: 100%;
			padding: 16px;
			height: calc(100% - 60px);
			overflow-y: auto;
			border: 1px solid #ccc;
			background-color: #fff;
			padding: 16px;
			box-sizing: border-box;
			overflow-y: auto;



			.stockTitle {
				width: 100%;
				height: 50px;
				background-color: #165DFF;
				text-align: center;
				color: #fff;
				position: relative;

				.iconBack {
					position: absolute;
					left: 0px;
					top: 50%;
					transform: translate(0, -50%);
				}
			}

			.deviceTypeList {
				margin-top: 8px;



				.deviceTypeInfo {
					width: 220px;
					height: 80px;
					background-color: #165DFF;
					position: relative;
					padding: 8px;
					box-sizing: border-box;
					color: #fff;
					border-radius: 8px;
					margin-left: 8px;
					font-size: 12px;
					line-height: 16px;

					.iconStatus {
						position: absolute;
						top: 16px;
						right: 8px;
						transform: translate(0%, -50%);
					}

					.iconRight {
						position: absolute;
						top: 50%;
						right: 8px;
						transform: translate(0%, -50%);
					}
				}
			}

		}

		.popupBox {
			width: 300px;
			height: calc(100vh - 100px);
			padding: 16px;
			box-sizing: border-box;

			.title {
				height: 34px;
				line-height: 34px;
				text-align: center;
				font-family: 600;
				font-size: 16px;
			}

			.checkListMain {
				// height: 420px;
				height: calc(100vh - 300px);
				overflow-y: auto;
			}

			.mt16 {
				margin-top: 16px;
			}


			.errBorder {
				border: 1px solid #165DFF;
			}

			.deviceTypeInfo {
				width: 220px;
				height: 80px;
				background-color: #165DFF;
				position: relative;
				padding: 8px;
				box-sizing: border-box;
				color: #fff;
				border-radius: 8px;
				margin-left: 8px;
				font-size: 12px;
				line-height: 16px;

				.iconStatus {
					position: absolute;
					top: 16px;
					right: 8px;
					transform: translate(0%, -50%);
				}

				.iconRight {
					position: absolute;
					top: 50%;
					right: 8px;
					transform: translate(0%, -50%);
				}
			}

			.popupBtn {
				width: 100%;
				margin: 0 auto;
				height: 48px;
				display: flex;
				align-items: center;
				justify-content: space-evenly;
				margin-top: 16px;
			}
		}

	}
</style>